package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.dto.SimpleCategoryDTO;
import com.sc.nft.entity.vo.MallCategoryVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MallCategory;
import com.sc.nft.mapper.MallCategoryMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * IP商城分类表(sc_mall_category)数据DAO
 *
 * @author zxy
 * @description IP商城
 * @since 2023-05-10 16:59:01
 */
@Slf4j
@Repository
public class MallCategoryDao extends ServiceImpl<MallCategoryMapper, MallCategory> {


    public List<MallCategory> getMallCategoryList(Long daoId) {
        LambdaQueryWrapper<MallCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallCategory::getDaoId, daoId);
        wrapper.eq(MallCategory::getSearchCondition, true);
        wrapper.orderByDesc(MallCategory::getSort);
        return list(wrapper);
    }

    public IPage<MallCategoryVO> categoryPage(Page page, String name, Boolean isVirtual) {
        return baseMapper.categoryPage(page, name,isVirtual);
    }

    public MallCategory getByName(String name) {
        LambdaQueryWrapper<MallCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallCategory::getName, name);
        return getOne(wrapper);
    }

    public List<MallCategory> newCategoryList(Boolean isVirtual) {
        LambdaQueryWrapper<MallCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallCategory::getIsShow, true);
        wrapper.eq(MallCategory::getIsVirtual, isVirtual);
        wrapper.orderByDesc(MallCategory::getSort);
        return list(wrapper);
    }
}